package com.wf.smartcomm.server.admin.action;

import java.util.HashMap;

import javax.annotation.Resource;

import org.json.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.wf.smartcomm.server.service.UnLockService;
import com.wf.smartcomm.server.util.StringUtil;

@Controller
@Scope("prototype")
public class UnlockAction extends BaseAction {
	
	@Resource
	private UnLockService unlockServiceImpl;
	
	public void list() throws Exception{
		String mid = request.getParameter("mid");
		String aoData = request.getParameter("aoData");
		String sEcho = "";
		String iDisplayStart = "";
		String iDisplayLength = "";
		String sSearch = "";
		
		JSONObject jo = new JSONObject(aoData);
		sEcho = jo.getString("sEcho");
		iDisplayStart = jo.getString("iDisplayStart");
		iDisplayLength = jo.getString("iDisplayLength");
		sSearch = jo.getString("sSearch");
		
		page.setBeginIndex(Integer.parseInt(iDisplayStart));
		page.setPageSize(Integer.parseInt(iDisplayLength));
		
		if (!StringUtil.isEmpty(sSearch)) {
			unlockServiceImpl.queryByKey(mid,sSearch, page);
		}else {
			unlockServiceImpl.listByUm(mid,page);
		}
		
		int  initEcho = Integer.parseInt(sEcho)+1;
		int count = page.getTotalCount();
		HashMap<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("iTotalRecords", count);
		dataMap.put("sEcho",initEcho);
		dataMap.put("iTotalDisplayRecords", count);
		dataMap.put("aaData", page.getDataList());
		printJsonData(outGson.toJson(dataMap));
	}
}
